package com.fast.tcc.controller;

import com.fast.tcc.model.TccRequest;
import com.fast.tcc.service.CoordinateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Auther: wangzun
 * @Date: 2018/9/14 14:23
 * @Description:TCC资源管理
 */

@RestController
@RequestMapping(value = "/api/v1",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class CoordinateController {
    private static final String COORDINATE_URI_PREFIX = "/coordinator";

    @Autowired
    private CoordinateService tccService;

    @ApiOperation(value = "确认预留资源",notes="")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @RequestMapping(value = COORDINATE_URI_PREFIX+"/confirmation",method = RequestMethod.PUT)
    public void confirm(@Valid @RequestBody TccRequest request , BindingResult result) {
        tccService.confrim(request);
    }

    @ApiOperation(value = "撤销预留资源",notes="")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @RequestMapping(value = COORDINATE_URI_PREFIX+"/cancellation",method = RequestMethod.PUT)
    public void cancel(@Valid @RequestBody TccRequest request , BindingResult result) {
        tccService.cancel(request);
    }


}
